home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ptv1n1.arc / L7.ASM < prev    next >
Assembly Source File  |  1990-06-08  |  1KB  |  56 lines

  1. ;
  2. ; *** Listing 7 ***
  3. ;
  4. ; Assembler subroutine to perform a 16-bit checksum on a block of
  5. ; bytes 1 to 64Kb in size. Adds checksum for block into passed-in
  6. ; checksum.
  7. ;
  8. ; Call as:
  9. ;    void ChecksumChunk(unsigned char *Buffer,
  10. ;        unsigned int BufferLength, unsigned int *Checksum);
  11. ;
  12. ; where:
  13. ;    Buffer = pointer to start of block of bytes to checksum
  14. ;    BufferLength = # of bytes to checksum (0 means 64K, not 0)
  15. ;    Checksum = pointer to unsigned int variable checksum is
  16. ;        stored in
  17. ;
  18. ; Parameter structure:
  19. ;
  20. Parms    struc
  21.         dw    ?    ;pushed BP
  22.         dw    ?    ;return address
  23. Buffer        dw    ?
  24. BufferLength    dw    ?
  25. Checksum    dw    ?
  26. Parms    ends
  27. ;
  28.     .model small
  29.     .code
  30.     public _ChecksumChunk
  31. _ChecksumChunk    proc    near
  32.     push    bp
  33.     mov    bp,sp
  34.     push    si        ;save C's register variable
  35. ;
  36.     cld            ;make LODSB increment SI
  37.     mov    si,[bp+Buffer]    ;point to buffer
  38.     mov    cx,[bp+BufferLength] ;get buffer length
  39.     mov    bx,[bp+Checksum] ;point to checksum variable
  40.     mov    dx,[bx]        ;get the current checksum
  41.     sub    ah,ah        ;so AX will be a 16-bit value
  42.                 ; after LODSB
  43. ChecksumLoop:
  44.     lodsb            ;get the next byte
  45.     add    dx,ax        ;add it into the checksum total
  46.     loop    ChecksumLoop    ;continue for all bytes in block
  47.     mov    [bx],dx        ;save the new checksum
  48. ;
  49.     pop    si        ;restore C's register variable
  50.     pop    bp
  51.     ret
  52. _ChecksumChunk    endp
  53.     end
  54.  
  55.  
  56.